﻿package cminus.exception;

import cminus.CminusException;

@SuppressWarnings("serial")
public class ParseException extends CminusException {
	
	/**定义C1的语法分析异常类型*/
	public static final int ParseError = 2000;
	public static final int MissingRightBrace = 2001;
	public static final int MissingLeftBrace = 2002;
	public static final int IllegalStatement = 2003;
	public static final int MissingSemicolon = 2004;
	public static final int MissingEQUAL = 2005;
	public static final int MissingRightParenthesis = 2006;
	public static final int MissingLeftParenthesis = 2007;
	public static final int WrongExpression = 2008;
	public static final int WrongAddress = 2009;

	/**
	 * 
	 * @param lineNumber 行号
	 * @param columnNumber 列号
	 * @param exceptionType 异常类型
	 * @param exceptionLevel 异常等级
	 */
	public ParseException(int lineNumber, int columnNumber,
			int exceptionType,  int exceptionLevel) {		
		super(lineNumber, columnNumber, exceptionType, exceptionLevel);
		switch(exceptionType){
		case 2000:
			super.exceptionMsg = "parse error";
			break;
		case 2001:
			super.exceptionMsg = "missing '}'";
			break;
		case 2002:
			super.exceptionMsg = "missing '{'";
			break;
		case 2003:
			super.exceptionMsg = "illegal statement";
			break;
		case 2004:
			super.exceptionMsg = "missing ';'";
			break;
		case 2005:
			super.exceptionMsg = "missing '='";
			break;
		case 2006:
			super.exceptionMsg = "missing ')'";
			break;
		case 2007:
			super.exceptionMsg = "missing '('";
			break;
		case 2008:
			super.exceptionMsg = "wrong expression";
			break;
		case 2009:
			super.exceptionMsg = "wrong address";
			break;
		//	default:
		}
		//super.exceptionMsg = lineNumber +" "+ columnNumber +" "+ String.valueOf(exceptionType);
	}
	
	public ParseException(){
		//TODO exceptionMsg需要从XML文件读取
		super(0, 0, ParseException.ParseError , CminusException.LevelError);
	}

	@Override
	public String getExceptionMsg() {
		return "[Parse error]Line " + super.lineNumber + ", Column " + super.columnNumber + " : " + super.exceptionMsg + "\n";
		//return super.exceptionMsg;
	}

}